package com.wuye.parking.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.wuye.basic.mapper.WyCommunityMapper;
import com.wuye.basic.service.IWyCommunityService;
import com.wuye.charge.service.IWyCostService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wuye.common.annotation.Log;
import com.wuye.common.core.controller.BaseController;
import com.wuye.common.core.domain.AjaxResult;
import com.wuye.common.enums.BusinessType;
import com.wuye.parking.domain.WyRegion;
import com.wuye.parking.service.IWyRegionService;
import com.wuye.common.utils.poi.ExcelUtil;
import com.wuye.common.core.page.TableDataInfo;

/**
 * 区域Controller
 * 
 * @author avalon
 * @date 2024-11-23
 */
@RestController
@RequestMapping("/parking/region")
public class WyRegionController extends BaseController
{
    @Autowired
    private IWyRegionService wyRegionService;
    @Autowired
    private IWyCommunityService iWyCommunityService;
    @Autowired
    private IWyCostService iWyCostService;

    /**
     * 查询区域列表
     */
    @PreAuthorize("@ss.hasPermi('parking:region:list')")
    @GetMapping("/list")
    public TableDataInfo list(WyRegion wyRegion)
    {
        startPage();
        List<WyRegion> list = wyRegionService.selectWyRegionList(wyRegion);
        for (WyRegion wyRegion1 : list) {
            wyRegion1.setWyCost(iWyCostService.selectWyCostByCostId(wyRegion1.getCostId()));
            wyRegion1.setCommunity(iWyCommunityService.selectWyCommunityByCommunityId(wyRegion1.getcommunityId()));
        }
        return getDataTable(list);
    }

    /**
     * 导出区域列表
     */
    @PreAuthorize("@ss.hasPermi('parking:region:export')")
    @Log(title = "区域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WyRegion wyRegion)
    {
        List<WyRegion> list = wyRegionService.selectWyRegionList(wyRegion);
        ExcelUtil<WyRegion> util = new ExcelUtil<WyRegion>(WyRegion.class);
        util.exportExcel(response, list, "区域数据");
    }

    /**
     * 获取区域详细信息
     */
    @PreAuthorize("@ss.hasPermi('parking:region:query')")
    @GetMapping(value = "/{regionId}")
    public AjaxResult getInfo(@PathVariable("regionId") Long regionId)
    {
        return success(wyRegionService.selectWyRegionByRegionId(regionId));
    }

    /**
     * 新增区域
     */
    @PreAuthorize("@ss.hasPermi('parking:region:add')")
    @Log(title = "区域", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WyRegion wyRegion)
    {
        return toAjax(wyRegionService.insertWyRegion(wyRegion));
    }

    /**
     * 修改区域
     */
    @PreAuthorize("@ss.hasPermi('parking:region:edit')")
    @Log(title = "区域", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WyRegion wyRegion)
    {
        return toAjax(wyRegionService.updateWyRegion(wyRegion));
    }

    /**
     * 删除区域
     */
    @PreAuthorize("@ss.hasPermi('parking:region:remove')")
    @Log(title = "区域", businessType = BusinessType.DELETE)
	@DeleteMapping("/{regionIds}")
    public AjaxResult remove(@PathVariable Long[] regionIds)
    {
        return toAjax(wyRegionService.deleteWyRegionByRegionIds(regionIds));
    }
}
